package com.mangocheese.subject.common.entity;

import com.mangocheese.subject.common.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class CommonResult<T> {

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public static <T> CommonResult<T> ok(){
        return ok(null);
    }

    public static <T> CommonResult<T> ok(T data){
        return ok(data,ResultCodeEnum.SUCCESS.getDesc());
    }

    public static <T> CommonResult<T> ok(T data, String message){
        CommonResult<T> result = new CommonResult<>();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> CommonResult<T> fail(){
        return fail(null);
    }

    public static <T> CommonResult<T> fail(T data){
        return fail(data,ResultCodeEnum.SUCCESS.getDesc());
    }

    public static <T> CommonResult<T> fail(T data, String message){
        CommonResult<T> result = new CommonResult<>();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(message);
        result.setData(data);
        return result;
    }
}
